package io.dy.config;

import io.dy.bean.Bean_01;
import io.dy.bean.Bean_02;
import io.dy.bean.Bean_03;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.GenericApplicationContext;

/**
 * @author : dmj
 * @date: 2024/6/3 6:53 下午
 * @description: 手动添加监听器
 */
//@Configuration
public class Dy_04 {

    public static void main(String[] args) throws Exception {
        //1、创建 SpringApplication
        SpringApplication application = new SpringApplication(Dy_04.class);

        //2、添加监听器器到容器中
        application.addListeners(new ApplicationListener<ApplicationEvent>() {
            @Override
            public void onApplicationEvent(ApplicationEvent event) {
                System.out.println("\t 监听到的事件为:" + event.getClass().getSimpleName());
            }
        });

        //3、run容器
        ConfigurableApplicationContext context = application.run(args);
        context.close();
    }


    @Bean
    public Bean_01 bean_01(){
        return new Bean_01();
    }

    @Bean
    public Bean_02 bean_02(){
        return new Bean_02();
    }

    @Bean
    public TomcatServletWebServerFactory servletWebServerFactory(){
        return new TomcatServletWebServerFactory();
    }
}
